package com.example.qihuibao.module.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

/**
 * 监听自动安装成功
 */
public class InstallReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent == null || intent.getAction() == null || !intent.getAction().equals(Intent.ACTION_PACKAGE_REPLACED)) return;
        Log.e("install","安装成功");
        String appPackageName = context.getPackageName();
        if (intent.getAction().equals(Intent.ACTION_PACKAGE_REPLACED)) {
            String packageName = intent.getData().getEncodedSchemeSpecificPart();
            if (packageName.equals(appPackageName)) {
                // 重新启动APP
                Intent intentToStart = context.getPackageManager().getLaunchIntentForPackage(packageName);
                context.startActivity(intentToStart);
            }
        }

    }

}
